package cn.sofwin.day0116;

/**
 * 数组
 */
public class Test01 {
    public static void main(String[] args) {
        int[] a = new int[]{3, 5, 6, 2, 8, 0};
        display(a);
        System.out.println("MAX=" + getMax(a));
        System.out.println("MIN=" + getMin(a));
        swap(a, 1, 3);
        display(a);
        reverse(a);display(a);
    }

    static void display(int[] a){
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i < a.length - 1){
                System.out.print("\t");
            }
        }
        System.out.println();
    }

    static int getMax(int[] a){
        int max = 0;
        for (int n : a) {
            max = max < n ? n : max;
        }
        return max;
    }

    static int getMin(int[] a){
        int min = a[0];
        for (int i = 1; i < a.length; i++){
            min = min > a[i] ? a[i] : min;
        }
        return min;
    }

    static void swap(int[] a, int i, int j){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    static void reverse(int[] a){
        for (int i = 0; i < a.length / 2; i++) {
            swap(a, i, a.length - 1 - i);
        }
    }
}
